'''
 This class is an test of how to use the nodes of the tree class.
 
 author: Samuel T. C. Santos
 data  : 2013/14/04
 trunk/PyCodes/codes-poo/node_test.py
 
'''
from node import Node

class NodeTest:

	def __init__(self):
		print ("init node test...")
		
	'''
	This method show how to use the node class
	and create someone tests for Node class.
	
	'''
	def run(self):
		node = Node(None)
		
		assert( node.isEmpty() == True)
		
		assert(node.getParent() == None)
		assert(node.getLeft() == None)
		assert(node.getRight() == None)
		assert(node.getData() == None)
		
		node.setData(4)
		
		parent = Node(None)
		left = Node(11)
		right = Node(13)
		
		node.setParent(parent)
		assert(node.isRoot() == True)
		
		node.setLeft(left)
		node.setRight(right)
		
		'''
		 this is the shape of the tree.
		             None  (parent)
				           |
		               4  (node)
			           /   \
	     (left)  11	    13  (right)
			        /  \   /  \
		     None None None None
		'''
		
		#check os set and get	
		assert(node.getParent().isEmpty() == True)
		assert(node.getLeft() == left)
		assert(node.getLeft().isEmpty() ==  False)
		assert(node.getRight() == right)
		assert(node.getRight().isEmpty() == False)
		
		# this node should be the root
		assert(node.isRoot() == True)
		
		# this node no should be leaf,
    # because it has two children.
		assert(node.isLeaf() == False)
		
		#should be leaf
		assert(right.isLeaf() == True)
		assert(left.isLeaf() == True)
		
		## more tests the children
		assert( node.getLeft().getLeft() == None)
		assert( node.getLeft().getRight() == None)
		
		assert( node.getRight().getLeft() == None)
		assert( node.getRight().getRight() == None)
		
		print("Done tests OK!")
		
if __name__ == '__main__':
	test = NodeTest()
	test.run()
